<?= $this->Html->css('multi-inputs', null, array('inline'=>false)) ?>
<?= $this->Html->script('multi-inputs.asset', array('inline'=>false)) ?>

<p class="entity-table">
    <?= $this->Html->link("&laquo; nazad", "/campaigns", array( 'escape' => false ))?>
    
    <span class="actions visible form button-set">
    <? if (!empty($data['Campaign']['id'])): ?>
    <? $entityId = $data['Campaign']['id'] ?>
    
        <?= $this->Form->button('Kreiraj fakturu', array(
            'type'    => 'button',
            'onclick' => "location.href='/invoices/create/?campaign={$entityId}'"
        )) ?><?= $this->Form->button('Obriši', array(
            'class'   => 'delete',
            'onclick' => "if (confirm('Da li želite da obrišete kampanju?')){location.href = '/campaigns/remove/{$entityId}'}"
        ))?>
    <? endif ?>
    </span>
</p>
<?= $this->Form->create('Campaign', array('url' => '/campaigns/save')) ?>

    <?= $this->Form->hidden('id', array( 'value' => (int)@$data['Campaign']['id'])) ?>
    
    <p><?= $this->Form->label('name', 'Naziv:') ?>
    <?= $this->Form->text('name', array(
        'value' => @$data['Campaign']['name'],
        'class' => 'large'
    )) ?></p>
    
    <p><?= $this->Form->label('client_id', 'Klijent:') ?>
    <?= $this->Form->select('client_id', $clients, array(
        'value' => @$data['Client']['id'],
        'empty' => false
    )) ?></p>
    
    <p class="left"><?= $this->Form->label('location_id', 'Lokacije:', array('class'=>'left')) ?>
    <? if (empty($data['CampaignsLocation'])) {
        $data['CampaignsLocation'][] = array(
            'id' => 0,
            'production' => 1,
            'mount' => 1,
            'start' => '',
            'end'   => '',
            'rabat' => '',
            'avans' => '',
            'campaign_id' => @$data['Campaign']['id']
        );
    } ?>
        
    <span class="multi-inputs left">
        <? foreach ($data['CampaignsLocation'] as $k=>$campaigns_location): ?>
        <span class="multi-input">
            <?= $this->Form->hidden("CampaignsLocation.{$k}.id", array( 'value' => @$campaigns_location['id'])) ?>
            <?= $this->Form->hidden("CampaignsLocation.{$k}.campaign_id", array( 'value' => @$campaigns_location['campaign_id'])) ?>
            <?= $this->Form->select("CampaignsLocation.{$k}.location_id", $locations, array(
                'value' => @$campaigns_location['location_id'],
                'empty' => false
            )) ?>
            
            <?= $this->element('production_picker', array(
                'name'  => "CampaignsLocation.{$k}.production",
                'value' => $campaigns_location['production'],
                'label' => $this->Form->label("CampaignsLocation.{$k}.production", 'Produkcija:', array(
                    'class'=>'auto'
                ))
            )) ?>
            
            <?= $this->Form->label('start', 'Period zakupa:', array('class'=>'auto')) ?>
            <?= $this->Form->text("CampaignsLocation.{$k}.start", array(
                'value' => $campaigns_location['start'],
                'class' => 'datepicker',
                'required' => false
            )) ?> - 
            <?= $this->Form->text("CampaignsLocation.{$k}.end", array(
                'value' => $campaigns_location['end'],
                'class' => 'datepicker',
                'required' => false
            )) ?>
            
            <?= $this->Form->label('rabat', 'Rabat:', array('class'=>'auto')) ?>
            <?= $this->Form->text("CampaignsLocation.{$k}.rabat", array(
                'value' => $campaigns_location['rabat'],
                'class' => 'number',
                'required' => false
            )) ?>%
            
            <?= $this->Form->label('avans', 'Avans:', array('class'=>'auto')) ?>
            <?= $this->Form->text("CampaignsLocation.{$k}.avans", array(
                'value' => $campaigns_location['avans'],
                'class' => 'number',
                'required' => false
            )) ?>%
        </span>
        <? endforeach ?>
    </span></p>
    <br clear="all">
    
    <?= $this->Form->button('Sačuvaj') ?>
<?= $this->Form->end() ?>
